package com.ruoyi.rms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rms.domain.AssessMessage;
import com.ruoyi.rms.service.IAssessMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价信息Controller
 * 
 * @author wyl
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/rms/assess")
public class AssessMessageController extends BaseController
{
    @Autowired
    private IAssessMessageService assessMessageService;

    /**
     * 查询评价信息列表
     */
//    @PreAuthorize("@ss.hasPermi('rms:assess:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssessMessage assessMessage)
    {
        startPage();
        List<AssessMessage> list = assessMessageService.selectAssessMessageList(assessMessage);
        return getDataTable(list);
    }

    /**
     * 根据订单查询评论
     * @param orderId
     * @return
     */
    @GetMapping("/selectAssessByOrderId/{orderId}")
    public AjaxResult selectAssessByOrderId(@PathVariable("orderId") Long orderId) {
        return AjaxResult.success(assessMessageService.selectAssessByOrderId(orderId));
    }

    /**
     * 导出评价信息列表
     */
//    @PreAuthorize("@ss.hasPermi('rms:assess:export')")
    @Log(title = "评价信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssessMessage assessMessage)
    {
        List<AssessMessage> list = assessMessageService.selectAssessMessageList(assessMessage);
        ExcelUtil<AssessMessage> util = new ExcelUtil<AssessMessage>(AssessMessage.class);
        util.exportExcel(response, list, "评价信息数据");
    }

    /**
     * 获取评价信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('rms:assess:query')")
    @GetMapping(value = "/{assessId}")
    public AjaxResult getInfo(@PathVariable("assessId") Long assessId)
    {
        return success(assessMessageService.selectAssessMessageByAssessId(assessId));
    }

    /**
     * 新增评价信息
     */
//    @PreAuthorize("@ss.hasPermi('rms:assess:add')")
    @Log(title = "评价信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssessMessage assessMessage)
    {
        return assessMessageService.insertAssessMessage(assessMessage) > 0 ? AjaxResult.success("评价成功") : AjaxResult.error("此订单未付款，不能评价");
    }

    /**
     * 修改评价信息
     */
//    @PreAuthorize("@ss.hasPermi('rms:assess:edit')")
    @Log(title = "评价信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssessMessage assessMessage)
    {
        return toAjax(assessMessageService.updateAssessMessage(assessMessage));
    }

    /**
     * 删除评价信息
     */
//    @PreAuthorize("@ss.hasPermi('rms:assess:remove')")
    @Log(title = "评价信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assessIds}")
    public AjaxResult remove(@PathVariable Long[] assessIds)
    {
        return toAjax(assessMessageService.deleteAssessMessageByAssessIds(assessIds));
    }
}
